package Demo;

public class Demo34 {

    public static void main(String[] args) {
        abstractShape s = getFactory.getInstance("squareness", 11.0, 11.0);
        double area = s.area();
        System.out.println(area);
    }
}

abstract class abstractShape {
    abstract public double area();

    abstract public double perimeter();


}

class squareness extends abstractShape {
    private double length_left;
    private double length_up;

    public squareness(double length_left, double length_up) {
        this.length_left = length_left;
        this.length_up = length_up;
    }

    public double getLength_left() {
        return length_left;
    }

    public void setLength_left(double length_left) {
        this.length_left = length_left;
    }

    public double getLength_up() {
        return length_up;
    }

    public void setLength_up(double length_up) {
        this.length_up = length_up;
    }

    @Override
    public double area() {

        return this.length_left * this.length_up;
    }

    @Override
    public double perimeter() {
        return 2 * (this.length_left + this.length_up);
    }
}

class round extends abstractShape {
    private double radius;

    public round(double radius) {
        this.radius = radius;
    }

    private double pai = 3.14;


    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {
        return this.pai * this.radius * this.radius;
    }

    @Override
    public double perimeter() {
        return this.pai * this.radius * 2;
    }
}

class getFactory {
    public static abstractShape getInstance(String className, double... args) {
        if (className.equalsIgnoreCase("squareness")) {
            return new squareness(args[0], args[1]);
        } else if ("round".equalsIgnoreCase(className)) {
            return new round(args[0]);
        } else {

            return null;
        }
    }
}


